<?php
include_once("includes/global.php");

$mysql_server_name='114.55.5.26'; //改成自己的mysql数据库服务器
$mysql_username='tuangouuser'; //改成自己的mysql数据库用户名
$mysql_password='tuangou616'; //改成自己的mysql数据库密码
$mysql_database='mallyangwanyi'; //改成自己的mysql数据库名
//连接数据库
$conn=mysqli_connect($mysql_server_name,$mysql_username,$mysql_password) or die("error connecting") ;
mysqli_query($conn, "set names 'utf8mb4'"); //数据库输出编码 应该与你的数据库编码保持一致
mysqli_select_db($conn, $mysql_database); //打开数据库

$query = "SELECT * FROM tb_member where id < 2000";
$result = mysqli_query($conn, $query);


/* associative array */

while($row = mysqli_fetch_array($result))
{
    
    $mysql_server_name='rdsjg3zfk4i0wrm5y777o.mysql.rds.aliyuncs.com'; //改成自己的mysql数据库服务器
    $mysql_username='newyangwanyi'; //改成自己的mysql数据库用户名
    $mysql_password='yangwanyi616'; //改成自己的mysql数据库密码
    $mysql_database='new_ywy'; //改成自己的mysql数据库名
    //连接数据库
    $conn1=mysqli_connect($mysql_server_name,$mysql_username,$mysql_password) or die("error connecting") ;
    mysqli_query($conn1, "set names 'utf8mb4'"); //数据库输出编码 应该与你的数据库编码保持一致
    mysqli_select_db($conn1, $mysql_database); //打开数据库
    
    
    //导入用户数据
    $sql = 'insert into haiou_member (userid,phoneid,username,password,open_type,open_secretid,name,signature,sex,age,mobile,email,
        birthday,qq,weixin,provinceid,cityid,areaid,area,logo,sns_medal_logo,ip,points,growth,status,grade,update_date,regtime
        ,chkstatus,client_platform,client_system,lastlogintime,create_time,tarento_member_id,is_tarento)
        VALUES('.$row['id'].',"","'.$row['username'].'","12140118",1,"'.$row['openId'].'","'.$row['shopName'].'","",'.$row['theSex'].',0,"'.$row['thePhone'].'","'.$row['theEmail'].'",
            "0000-00-00","'.$row['theQQ'].'","'.$row['weixinId'].'",0,0,0,0,"http://img.diandianna.com/'.$row['theFace'].'","","",'.$row['loginNum'].',0,'.$row['verifycw'].',"'.$row['theCharacter'].'",0,"'.$row['addTime'].'"
            ,0,4,3,'.strtotime($row['lastLoginTime']).',"'.$row['addTime'].'",'.$row['belongToCast'].', '.$row['theCharacterVerify'].')';
    mysqli_query($conn1, $sql);
    //导入用户关联关系
    
    //查询用户层级关系；递归向上查询
    $relations = '';
    $thecaharacter = $row;
    
    if($thecaharacter['theCharacter'] < 3){
        $relations = $thecaharacter['id'];
        $str = 1;
        while ($thecaharacter['userIsGood'] != 0 && $str == 1) {
            $sql_1 = "select id,userIsGood,theCharacter from tb_member where id = ".$thecaharacter['userIsGood']."";
            $strs = mysqli_query($conn, $sql_1);
            $thecaharacter = mysqli_fetch_array($strs);
            if ($thecaharacter['theCharacter'] == 3) {
                $relations = $thecaharacter['id'].",".$relations;
                $str = 0;
            }else{
                $relations = $thecaharacter['id'].",".$relations;
                $str = 1;
            }
        }
    }else{
        $relations = $row['id'];
    }
       
    $level = '';
    if($row['theCharacter'] == 3){
        $level = 1;
    }else if($row['theCharacter'] == 2){
        $level = 2;
    }else if($row['theCharacter'] == 1){
        $level = 3;
    }else{
        $level = 4;
    }
    
    
    $sqls = 'insert into haiou_tarento (member_id,direct_rec_mid,indirect_rec_mid,relations,invite_code,level,account,pay_password,lowest_rate,extra_point,total_bonus,status,create_time,create_user,have_discount_price,have_micro_shop,can_upgrade_shop)
                    values('.$row['id'].','.$row['userIsGood'].','.$row['belongToCast'].',"'.$relations.'","",'.$level.','.$row['theMoney'].',12140118,0,0,0,1,"'.$row['addTime'].'","",0,'.$row['type'].',0)';
    mysqli_query($conn1, $sqls);
        
    
    $sql_2 = 'insert into haiou_member_other_platform (userid,open_type,open_secretid,name,logo,client_platform,client_system,data,create_time)
            values('.$row['id'].',1,"'.$row['openId'].'","'.$row['shopName'].'","http://img.diandianna.com/'.$row['theFace'].'",1,1,"","'.$row['addTime'].'")';
    mysqli_query($conn1, $sql_2);
    
    if($row['type'] == 1){
        $shop = 'insert into haiou_micro_shop (member_id,logo,personal_qrcode,name,description,user_real_name,user_idcard,level,status,create_time) 
                value ('.$row['id'].',"http://img.diandianna.com/'.$row['theFace'].'","","'.$row['shopName'].'","","'.$row['theName'].'",'.$row['theSfzNum'].','.$level.','.$row['isPayCharacter'].',"'.date('Y-m-d H:i:s' ,time()).'")';
        mysqli_query($conn1, $shop);
    }
    
    
    mysqli_close($conn1);
}
mysqli_close($conn);


?>